// sm4_simple_test.c
#include <stdio.h>
#include <string.h>
#include <gmssl/sm4.h>

int main() {
    SM4_KEY key;
    unsigned char plaintext[] = "Hello SM4 Test!1234"; // 16字节
    unsigned char ciphertext[16];
    unsigned char decrypted[16];
    unsigned char key_bytes[16] = {
        0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF,
        0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10
    };
    int i;
    
    printf("=== SM4 Encryption Test ===\n");
    
    // 设置加密密钥
    sm4_set_encrypt_key(&key, key_bytes);
    
    // 加密
    sm4_encrypt(&key, plaintext, ciphertext);
    
    printf("Plaintext:  %s\n", plaintext);
    printf("Key:        ");
    for (i = 0; i < 16; i++) printf("%02x", key_bytes[i]);
    printf("\n");
    printf("Ciphertext: ");
    for (i = 0; i < 16; i++) printf("%02x", ciphertext[i]);
    printf("\n");
    
    // 设置解密密钥
    sm4_set_decrypt_key(&key, key_bytes);
    
    // 解密
    sm4_encrypt(&key, ciphertext, decrypted);
    
    printf("Decrypted:  %s\n", decrypted);
    
    // 验证解密是否正确
    if (memcmp(plaintext, decrypted, 16) == 0) {
        printf("✓ SM4 Test: PASS - Encryption/Decryption successful\n");
    } else {
        printf("✗ SM4 Test: FAIL - Decryption failed\n");
    }
    
    return 0;
}
